
#include "c_TextureResource.h"
#include "c_Texture.h"

wiigi::c_TextureResource::c_TextureResource( c_ResourceMgr* ResourceMgr )
:
   //Base class
   c_Resource( ResourceMgr ),
   //Data members
   m_FileName( ), //Default constructor
   m_Texture( 0 )
{
   
   return;  
}

bool wiigi::c_TextureResource::cache( void )
{
   if( 0 == m_Texture )
   {
      m_Texture = m_Engine->loadTexture( m_FileName.c_str() );
   }
   
   return m_Texture ? true : false;
}

bool wiigi::c_TextureResource::purge( void )
{
   if( m_Texture )
   {
      delete m_Texture;
      m_Texture = 0;
   }
   
   return true;  
}

bool wiigi::c_TextureResource::setParameter( const std::string& ParameterName, const std::string& ParameterValue )
{
   printf("c_TextureResource::setParameter: %s=%s\n", ParameterName.c_str(), ParameterValue.c_str() );
   
   bool Supported;
   Supported = true;
   
   if( ParameterName == "filename" )
   {
      setFileName( ParameterValue );
   }
   else
   {
      Supported = c_Resource::setParameter( ParameterName, ParameterValue );
   }
   
   return Supported;
}

wiigi::c_Texture* wiigi::c_TextureResource::getTexture( void )
{
   if( 0 == m_Texture )
   {
      cache();
   }
   
   printf("TR:getTexture(): %p\n", m_Texture );
   
   return m_Texture;
}
